<?php

class BaseAction extends Action
{
    protected $Categorys;
    protected $Mod = array();
    protected $Model;
    protected $_groupid;

    public function _initialize()
    {
        $SysConfig = getSysConfig();
        C($SysConfig);

        //网站异常页面
        C('TMPL_EXCEPTION_FILE',realpath($SysConfig['TMPL_EXCEPTION_FILE']));

        $this->Model = getCache('Model');

        foreach ($this->Model as $key => $val) {
            $this->Mod[$val['tablename']] = $val['id'];
        }

        //用户组
        $this->_groupid = !empty($_SESSION['user']['group_id']) ? $_SESSION['user']['group_id'] : 0;

        $langData = getCache('Lang');
        $default_lang = C('DEFAULT_LANG');

        $l = I('get.l', '');
        $lang = isset($langData[$l]) ? $l : $default_lang;

        define('LANG_NAME', $lang);
        define('LANG_ID', $langData[$lang]['id']);

        //当前模板主题
        $defaultTheme = $langData[$lang]['default_theme'];

        //检测是否是手机访问
        if (C('SUB_DOMAIN')) {
            // 开启手机域名
            import('ORG.Util.MobileDetect');
            $detect = new MobileDetect;
            if ($detect->isMobile() || $detect->isTablet() || C('SITE_WAP_DOMAIN') == $_SERVER['HTTP_HOST']) {
                $defaultTheme = $langData[$lang]['default_wap_theme'];
            }
        }

        C('DEFAULT_THEME', $defaultTheme);

        /* 模板相关配置 */
        $parseString = array(
            '__PUBLIC__' => __ROOT__ . '/public',
            '__STATIC__' => __ROOT__ . '/public/static',
            '__IMG__' => __ROOT__ . '/public/' . strtolower(GROUP_NAME) . '/' . $defaultTheme . '/images',
            '__JS__' => __ROOT__ . '/public/' . strtolower(GROUP_NAME) . '/' . $defaultTheme . '/js',
            '__CSS__' => __ROOT__ . '/public/' . strtolower(GROUP_NAME) . '/' . $defaultTheme . '/css',
        );
        C('TMPL_PARSE_STRING', $parseString);

        //获取栏目
        $this->Categorys = getCache('Category_' . $lang);

        //获取网站配置信息
        $config = getCache('Config_' . $lang);

        C('TMPL_CACHFILE_SUFFIX', $lang . C('TMPL_CACHFILE_SUFFIX'));

        $this->assign('Lang', $langData);
        $this->assign($config);
        $this->assign('Model', $this->Model);
        $this->assign('Cats', $this->Categorys);

        $current = !empty($_SERVER['HTTP_X_REWRITE_URL']) ? $_SERVER['HTTP_X_REWRITE_URL'] : $_SERVER['REQUEST_URI'];
        $this->assign('current', $current);
    }

    //验证码
    public function verify()
    {
        import("ORG.Util.Image");
        Image::buildImageVerify(4, 5, 'png',100,36);
    }
}